import { getCategoryListByTypeApi } from "@/api/category"
import { categoryItem } from "@/types/category"

/**
 * 获取菜品分类
 * @returns 
 */
export const useCatetory = () => {
  const [categoryList, setCategoryList] = useState<categoryItem[]>([])
  useEffect(() => {
    const getList = async () => {
      const res = await getCategoryListByTypeApi()
      setCategoryList(res.data)
    }
    getList()
  }, [])
  return {
    categoryList
  }
}

/**
 * 获取套餐分类
 * @returns 
 */
export const useSetmealCatetory = () => {
  const [categoryList, setCategoryList] = useState<categoryItem[]>([])
  useEffect(() => {
    const getList = async () => {
      const res = await getCategoryListByTypeApi(2)
      setCategoryList(res.data)
    }
    getList()
  }, [])
  return {
    categoryList
  }
}